<template>
  <div class="myDiv">

    <div ref="chart" style="width: 100; height: 320px;"></div>

  </div>
</template>

<script>
import * as echarts from 'echarts';
import { getBarData } from "@/api/hrmanagement/menhu";
export default {
  name: '',
  components:{
},
  props:{
},
  data(){
    return {
      datalist:[],
      // 柱状图数据
      barData: {
        // ECharts 配置项
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        xAxis: {
          type: 'category',
          data: ['大专', '本科', '研究生']
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: [15, 25, 15],
            type: 'bar',
            name: 'Sample Data',
            barMaxWidth: 40,
            itemStyle: {
              // 可以设置柱状图的样式，比如颜色等
              color: '#61a0a8'
            }
          }
        ]
      }
    }
  },
  watch:{
},
  computed:{
},
  methods:{
    renderBarChart() {
      const chart = echarts.init(this.$refs.chart);
      chart.setOption(this.barData);
    }
},
  created(){
   
  
},
  mounted(){
    getBarData().then(response => {
      console.log(response.data);
      this.datalist=response.data
 
      var xAxisData  =  this.datalist.map(item => item.name);
      var barxAxisData  =  this.datalist.map(item => item.value);
      console.log(xAxisData);
      console.log(barxAxisData);
this.barData.xAxis.data = xAxisData
this.barData.series[0].data = barxAxisData

this.renderBarChart();

      });
}
}
</script>
<style lang="scss" scoped>

</style>